﻿using UnityEngine;
using System.Collections;

public class Walk : StateMachineBehaviour
{
    [SerializeField]
    float m_MoveSpeed;
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (GameManager.Instance.GameState!=Constants.GameState_Common|| GameManager.Instance.GameState != Constants.GameState_Pause)
            animator.SetInteger(Constants.Text_AnimState, Constants.AnimState_Kid_Idle);
        else
        {
            Vector2 dir = GameManager.Instance.PlayerPlane.transform.position - animator.transform.position;
            animator.transform.right = Vector3.right * Mathf.Sign(dir.x);
            if (dir.sqrMagnitude > Constants.ThrowMaxRangeSqr * 0.8f)
            {
                if (Mathf.Abs(dir.x) > 0.06f)
                    animator.transform.Translate(m_MoveSpeed * Time.deltaTime, 0f, 0f);
            }
            else if (dir.sqrMagnitude > Constants.ThrowMinRangeSqr)
            {
                animator.SetInteger(Constants.Text_AnimState, Constants.AnimState_Kid_ThrowStone);
            }
            else
                animator.transform.Translate(-m_MoveSpeed * Time.deltaTime, 0f, 0f);
        }
    }
}
